package com.sec.android.app.myfiles.module.download.providerapps;

import android.app.DownloadManager;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Handler;

import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.download.DownloadObserverImp;

public class BrowserObserver extends AbsContentObserver {

    Cursor mCursor;
    Context mContext;

    public BrowserObserver(Handler handler, Context context, DownloadObserverImp observeImp) {
        super(handler, context, observeImp);
        mContext = context;
    }

    @Override
    protected Uri getUri() {
        return null;
    }

    @Override
    public void register() {
        DownloadManager dm = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
        DownloadManager.Query query = new DownloadManager.Query();

        try {
            mCursor = dm.query(query);
            if (mCursor != null) {
                mCursor.registerContentObserver(this);
            }
        } catch (SQLiteException e) {
            Log.e(this, e.getMessage());
        }
    }

    @Override
    public void unregister() {
        if (mCursor != null) {
            mCursor.unregisterContentObserver(this);
            mCursor.close();
        }
    }
}
